package com.xb.loan.cashier.biz.job;

import com.xb.loan.util.qrtz.TaskScheduleManager;
import com.xb.loan.util.qrtz.task.AbstractCronTask;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

public class JobInit implements ApplicationContextAware {

    private ApplicationContext ctx;
    // 充值查询任务触发时间
    private String mChargeQueryExpression;
    // 充值回推任务触发时间
    private String mChargePushExpression;
    // 提现分批任务触发时间
    private String mEncashFetchExpression;
    // 提现任务触发时间
    private String mEncashExpression;
    // 提现查询任务触发时间
    private String mEncashQueryExpression;
    // 提现回推任务触发时间
    private String mEncashPushExpression;
    // 支付宝提现退票任务触发时间
    private String mAlipayRefundExpression;
    //平台充值对账任务触发时间
    private String mPlatAccountChargeExpression;
    //平台提现对账任务触发时间
    private String mPlatAccountEncashExpression;
    //第三方提现对账任务触发时间
    private String mEncashAccountExpression;
    //第三方充值对账任务触发时间
    private String mChargeAccountExpression;
    
    public void init(){
        TaskScheduleManager manager = (TaskScheduleManager) ctx.getBean("taskScheduleManager");
        
        // 充值查询任务
        AbstractCronTask job = new ChargeQueryJob();
        job.setJobName(job.getClass().getSimpleName());
        job.setCron_expression(mChargeQueryExpression);
        manager.shedule(job);
        // 充值回推任务
        job = new PlatPushChargeJob();
        job.setJobName(job.getClass().getSimpleName());
        job.setCron_expression(mChargePushExpression);
        manager.shedule(job);
        // 提现分批任务
        job = new EncashFetchJob();
        job.setJobName(job.getClass().getSimpleName());
        job.setCron_expression(mEncashFetchExpression);
        manager.shedule(job);
        // 提现任务
        job = new EncashJob();
        job.setJobName(job.getClass().getSimpleName());
        job.setCron_expression(mEncashExpression);
        manager.shedule(job);
        // 提现查询任务
        job = new EncashQueryJob();
        job.setJobName(job.getClass().getSimpleName());
        job.setCron_expression(mEncashQueryExpression);
        manager.shedule(job);
        // 提现回推任务
        job = new PlatPushEncashJob();
        job.setJobName(job.getClass().getSimpleName());
        job.setCron_expression(mEncashPushExpression);
        manager.shedule(job);
        // 支付宝提现退票任务
        job = new ThirdAccountEncashRefundAlipayJob();
        job.setJobName(job.getClass().getSimpleName());
        job.setCron_expression(mAlipayRefundExpression);
        manager.shedule(job);
        //第三方提现对账任务
        job = new ThirdAccountEncashJob();
        job.setJobName(job.getClass().getSimpleName());
        job.setCron_expression(mEncashAccountExpression);
        manager.shedule(job);
        //第三方充值对账任务
        job = new ThirdAccountChargeJob();
        job.setJobName(job.getClass().getSimpleName());
        job.setCron_expression(mChargeAccountExpression);
        manager.shedule(job);
        //平台充值对账任务
        job = new PlatAccountChargeJob();
        job.setJobName(job.getClass().getSimpleName());
        job.setCron_expression(mPlatAccountChargeExpression);
        manager.shedule(job);
        //平台提现对账任务
        job = new PlatAccountEncashJob();
        job.setJobName(job.getClass().getSimpleName());
        job.setCron_expression(mPlatAccountEncashExpression);
        manager.shedule(job);
    }

    @Override
    public void setApplicationContext(ApplicationContext ctx) throws BeansException {
        this.ctx = ctx;
    }

    public void setmChargeQueryExpression(String mChargeQueryExpression) {
        this.mChargeQueryExpression = mChargeQueryExpression;
    }

    public void setmChargePushExpression(String mChargePushExpression) {
        this.mChargePushExpression = mChargePushExpression;
    }

    public void setmEncashFetchExpression(String mEncashFetchExpression) {
        this.mEncashFetchExpression = mEncashFetchExpression;
    }

    public void setmEncashExpression(String mEncashExpression) {
        this.mEncashExpression = mEncashExpression;
    }

    public void setmEncashQueryExpression(String mEncashQueryExpression) {
        this.mEncashQueryExpression = mEncashQueryExpression;
    }

    public void setmEncashPushExpression(String mEncashPushExpression) {
        this.mEncashPushExpression = mEncashPushExpression;
    }

    public void setmAlipayRefundExpression(String mAlipayRefundExpression) {
        this.mAlipayRefundExpression = mAlipayRefundExpression;
    }

    public void setmPlatAccountChargeExpression(String mPlatAccountChargeExpression) {
        this.mPlatAccountChargeExpression = mPlatAccountChargeExpression;
    }

    public void setmPlatAccountEncashExpression(String mPlatAccountEncashExpression) {
        this.mPlatAccountEncashExpression = mPlatAccountEncashExpression;
    }

    public void setmEncashAccountExpression(String mEncashAccountExpression) {
        this.mEncashAccountExpression = mEncashAccountExpression;
    }

    public void setmChargeAccountExpression(String mChargeAccountExpression) {
        this.mChargeAccountExpression = mChargeAccountExpression;
    }

}
